import { IsOptional, IsString, IsNotEmpty } from 'class-validator';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { Decorator_DtoIsNumber_Base } from '@/common/decorators/dtoIsNumber';

import {
  Constant_Enum_Enum_Order_PayType,
  IConstant_Enum_Type_Order_PayType,
  Constant_Enum_Enum_Order_PayStatus,
  IConstant_Enum_Type_Order_PayStatus,
} from '@/common/constants/enum';

export class Order_Create_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '物品ID' })
  productId?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '物品ID' })
  couponId?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '分销码' })
  distributionCode?: string;
}

export class Order_Update_Dto extends PartialType(Order_Create_Dto) {
  @Decorator_DtoIsNumber_Base()
  @IsNotEmpty()
  id: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '平台单号，如支付宝平台单号' })
  payPlatformTradeNo?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    enum: Constant_Enum_Enum_Order_PayStatus,
    description: '订单状态',
  })
  status?: IConstant_Enum_Type_Order_PayStatus;
}

export class Order_Refund_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsNotEmpty()
  @ApiProperty({ description: '订单id' })
  orderId: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '退款金额' })
  refundPrice?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '退款备注' })
  refundRemark?: string;
}

export class Order_Pay_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsNotEmpty()
  @ApiProperty({ description: '物品ID' })
  orderId: number;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ description: '支付类型', enum: Constant_Enum_Enum_Order_PayType })
  payType: IConstant_Enum_Type_Order_PayType;
}

export class Order_Cancel_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsNotEmpty()
  @ApiProperty({ description: '订单ID' })
  id: number;
}

export class Order_Find_Dto {
  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  size?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  page?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({
    enum: Constant_Enum_Enum_Order_PayStatus,
    description: '订单状态',
  })
  status?: IConstant_Enum_Type_Order_PayStatus;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '用户Id' })
  userClientId?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '订单号' })
  orderNumber?: string;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '平台Id' })
  platformId?: number;

  @Decorator_DtoIsNumber_Base()
  @IsOptional()
  @ApiProperty({ description: '产品Id' })
  productId?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '平台单号，如支付宝平台单号' })
  payPlatformTradeNo?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    enum: Constant_Enum_Enum_Order_PayType,
    description: '订单支付类型',
  })
  payType?: IConstant_Enum_Type_Order_PayType;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '开始时间', type: 'bigint' })
  startTime?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({ description: '结束时间', type: 'bigint' })
  endTime?: number;
}
